package pl.edu.pk.mech.kkbus.repository;
import static pl.edu.pk.mech.kkbus.staticstrings.ExchangePointsProperty.*;
import static pl.edu.pk.mech.kkbus.staticstrings.NameEntity.NAME_ENTITY_EXCHANGE_POINTS;
import static pl.edu.pk.mech.kkbus.staticstrings.NameEntity.NAME_ENTITY_USERS;
import static pl.edu.pk.mech.kkbus.staticstrings.UserProperty.USER_AUTHORITIES;

import java.util.ArrayList;
import java.util.List;

import pl.edu.pk.mech.kkbus.datastore.common.SynchronizeCommon;
import pl.edu.pk.mech.kkbus.model.ExchangePoints;
import pl.edu.pk.mech.kkbus.model.Pojo;
import pl.edu.pk.mech.kkbus.model.User;
import pl.edu.pk.mech.kkbus.repository.BaseDAO;

import com.google.appengine.api.datastore.Entity;

public class ExchangePointsDAO extends BaseDAO{

	@Override
	public void fillProperty(Pojo pojo, Entity entity) {
		ExchangePoints exchangePoints = (ExchangePoints)pojo;
		entity.setProperty(EXCHANGE_POINTS_HASH, exchangePoints.getHash());
		entity.setProperty(EXCHANGE_POINTS_ID_AWARD, exchangePoints.getIdAward());
		entity.setProperty(EXCHANGE_POINTS_ID_USER, exchangePoints.getIdUser());
	}
	
	public ExchangePoints getAwardByHash(String hash){
		ExchangePoints exchangePoints = null;
		  Iterable<Entity> entityList = SynchronizeCommon.listEntities(NAME_ENTITY_EXCHANGE_POINTS, EXCHANGE_POINTS_HASH, hash);
		  for (Entity entity : entityList) {
			  exchangePoints = new ExchangePoints(entity);
		  }
		  return exchangePoints;
	}
	
	public List<ExchangePoints> getAllExchangePoints(){
		List<ExchangePoints> temp = new ArrayList<ExchangePoints>();
		  Iterable<Entity> entityList = SynchronizeCommon.listEntities(NAME_ENTITY_EXCHANGE_POINTS, null, null);
		  for (Entity entity : entityList) {
			  temp.add(new ExchangePoints(entity));
		  }
		  return temp;
	}
}
